package com.yunhe.policyfulfillment.authority.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.authority.domain.PolicyCompanyUser;
import com.yunhe.policyfulfillment.authority.model.ChangePassword;
import com.yunhe.policyfulfillment.authority.model.LoginUserApplyMatterQueryCondition;
import com.yunhe.policyfulfillment.authority.model.SupplementaryMaterials;
import com.yunhe.policyfulfillment.authority.service.PolicyCompanyUserService;
import com.yunhe.policyfulfillment.policyful.model.PersonalApplyMatterVo;
import com.yunhe.policyfulfillment.policyful.model.PolicyInfoApplyMatterDetailVo;
import com.yunhe.policyfulfillment.policyful.service.PolicyInfoApplyMatterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassName PersonalCenterController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/9/17 10:47
 * @Version 1.0
 **/
@Api(value = "PersonalCenter", description = "Model_PersonalCente", tags = {"个人中心"})
@RestController
@RequestMapping(value = "/personalCenter")
public class PersonalCenterController {

    @Autowired
    private PolicyCompanyUserService policyCompanyUserService;

    @Autowired
    private PolicyInfoApplyMatterService policyInfoApplyMatterService;


    @ApiOperation("查询企业用户信息")
    @GetMapping(value = "/findPolicyCompanyUserById")
    public ResponseEntity<ResultObject<PolicyCompanyUser>> findPolicyCompanyUserById(@RequestParam(value = "id",required = true) Integer id){
        return new ResponseEntity<>(new ResultObject(policyCompanyUserService.searchPolicyCompanyUserByPrimaryKey(id)), HttpStatus.OK);
    }

    @ApiOperation("修改密码")
    @PostMapping(value = "/changePolicyCompanyUserPassword")
    public ResponseEntity<ResultObject> changePolicyCompanyUserPassword(@RequestBody ChangePassword changePassword) throws ArgumentErrorException {
        policyCompanyUserService.changePolicyCompanyUserPassword(changePassword);
        return new ResponseEntity<>(new ResultObject(), HttpStatus.OK);
    }

    @ApiOperation("修改企业用户信息")
    @PostMapping(value = "/editPolicyCompanyUser")
    public ResponseEntity<ResultObject> editPolicyCompanyUser(@RequestBody PolicyCompanyUser policyCompanyUser){
        policyCompanyUserService.updatePolicyCompanyUserByPrimaryKeySelective(policyCompanyUser);
        return new ResponseEntity<>(new ResultObject(), HttpStatus.OK);
    }

    @ApiOperation("个人事项申请查询")
    @PostMapping(value = "/findLoginUserApplyMatterByCondition")
    public ResponseEntity<ResultObject<List<PersonalApplyMatterVo>>> findLoginUserApplyMatterByCondition(@RequestBody LoginUserApplyMatterQueryCondition loginUserApplyMatterQueryCondition){
        PageResult pageResult = policyInfoApplyMatterService.findLoginUserApplyMatterByCondition(loginUserApplyMatterQueryCondition);
        return new ResponseEntity<>(new ResultObject(pageResult), HttpStatus.OK);
    }

    @ApiOperation("根据id事项审批详情")
    @GetMapping("/findPolicyInfoApplyMatterById")
    public ResponseEntity<ResultObject<PolicyInfoApplyMatterDetailVo>> findPolicyInfoApplyMatterById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(policyInfoApplyMatterService.findPolicyInfoApplyMatterById(id)),HttpStatus.OK);
    }

    @ApiOperation("补充材料")
    @PostMapping("/supplementaryMaterials")
    public ResponseEntity<ResultObject> supplementaryMaterials(@RequestBody SupplementaryMaterials supplementaryMaterials) throws ArgumentErrorException {
        policyInfoApplyMatterService.supplementaryMaterials(supplementaryMaterials);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }


}
